package org.webdb.core;

import java.util.LinkedList;
import java.util.List;

public class ThreadContext {

    private static final ThreadLocal<List<Object>> threadLocal = new ThreadLocal<List<Object>>();

    public static void put(Object object) {
        List<Object> list = get();
        list.add(object);
    }

    public static List<Object> get() {
        List<Object> list = threadLocal.get();
        if (list == null) {
            list = new LinkedList<Object>();
            threadLocal.set(list);
        }

        return list;
    }

    public static void clean() {
        List<Object> list = threadLocal.get();
        if (list != null)
            list.clear();

        threadLocal.remove();
    }
}
